package engine.newUi
{
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.flag.ResourcesPath;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.tip.TipsMainLogic;
	import engine.ui.AlertUI;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.utils.setTimeout;
	
	import newx.com.config.StaticIni;
	import newx.com.control.button.NxButton;
	import newx.com.control.window.NxWindowEvent;

	/**
	 *副本扫荡逻辑 
	 * @author liuel
	 * 
	 */	
	public class WipeOutLogic
	{
		private static var _self :WipeOutLogic;
		private var _ui			:WipeOutUI;
		private var _model			:ModelLocator;
		private var _timer			:Timer;
		/**
		 *是否需要打开 
		 */		
		private var _needOpen:Boolean =true;
		/////////////////////////////////////普通副本/////////////////////////////////////////////
		/**单次需要的体力**/
		private var _oneThew		:int;
		/***单次需要的时间**/
		private var _oneTime		:int;
		private var _date			:Date;
		private var _wipeTarget	:int;
		//是否在扫荡中
		private var _isWipe		:Boolean;
		
		private var _vipLevel		:int;
		//剩余扫荡次数
		private var _wipeoutNum	:int =0;
		//精英当前层数
		private var _currlayer		:int =0;
		//精英剩余时间
		private var _time			:int =0;
		//扫荡类型 1普通副本扫荡 2精英副本扫荡
		private var _currType		:int =1;
		
		
		//////////////////////////////////////精英副本///////////////////////////////////////
		//精英副本可以扫荡的ID
		private var _currCanTarget:Array =[];
		private const  BUY_THEW_LEVEL:int =7;
		//扫荡次数(每次都从1开始)
		private var _CurrNum:int =0;
		//精英副本可以扫荡的目标个数；
		private var _targetTotal:int=0;
		//是否离线扫荡
		private var _isOfLine:Boolean =true; //
		//保存每层怪的数量
		private var npcArr:Array=[];
		private var _itemVec:Vector.<ItemResult>;
		private var addStr:String="";
		/**最大显示的轮次**/
		private const SHOW_LEN:int=20;
		
		/**
		 请求扫荡的次数 
		 */		
		private var _wipeoutTimes:int=0;
		public function WipeOutLogic()
		{
		}
		public static function getInstance():WipeOutLogic
		{
			if (_self == null) 
			{
				_self	=	new WipeOutLogic()
			}
			return _self;
		}
		public function Init():void 
		{
			_date	= new Date();
			_timer	= new Timer(1000);
			_ui		= WipeOutUI.getInstance();
			_model	= ModelLocator.getInstance();
			_ui.inputText.restrict = "0-9";
			_ui.inputText.maxChars = 8;
			//打開界面 
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FB_SWEEP_ONEN_WINDOW),onOpenUi);
			//扫荡开始
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FB_SWEEP_BEGIN),startWipe);
			//单次扫荡结算
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FB_SWEEP_CAL),updateResult);
			//禁地副本扫荡结算
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FORBIDDEN_SWEEP_INFO),updateForbiddenResult);

			//扫荡完成
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FB_SWEEP_FINISHED),endWipe);
			//扫荡副本的怪物
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FB_MONSTER_AMT),starget);
			_itemVec=new Vector.<ItemResult>();
		}
		public function AfterHide():void 
		{
			_ui.infoTxt.htmlText="";
			_ui.npclabel.text="";
			removeListener();
		}
		public function BeforeShow():void 
		{
//			SetCheckState();
			clearAll();
			addListener();
		}
		/**
		 * 添加事件
		 */
		private function addListener():void
		{
			_timer.addEventListener(TimerEvent.TIMER,PalyeTime);
			_ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,closeHandle);
			_ui.starBtn	.addEventListener(MouseEvent.CLICK, btnClickHandle);
//			_ui.endBtn	.addEventListener(MouseEvent.CLICK, btnClickHandle);
			_ui.checkBox.addEventListener(MouseEvent.CLICK, btnClickHandle);
			_ui.maxBtn	.addEventListener(MouseEvent.CLICK, btnClickHandle);
			_ui.inputText.addEventListener(KeyboardEvent.KEY_UP,InputClickHandle);
			_ui.clearBtn.addEventListener(MouseEvent.CLICK,btnClickHandle);
			_ui.clearBtn.addEventListener(MouseEvent.MOUSE_OVER,btnOverHandle);
			_ui.clearBtn.addEventListener(MouseEvent.MOUSE_OUT,btnOutHandle);
			_ui.jiaBtn.addEventListener(MouseEvent.CLICK,changeCount);
			_ui.jianBtn.addEventListener(MouseEvent.CLICK,changeCount);
			
		}
		/**
		 * 删除事件
		 */
		private function removeListener():void
		{
			_timer.removeEventListener(TimerEvent.TIMER,PalyeTime);
			_ui.windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE,closeHandle);
			_ui.starBtn	.removeEventListener(MouseEvent.CLICK, btnClickHandle);
//			_ui.endBtn	.removeEventListener(MouseEvent.CLICK, btnClickHandle);
			_ui.checkBox.removeEventListener(MouseEvent.CLICK, btnClickHandle);
			_ui.maxBtn	.removeEventListener(MouseEvent.CLICK, btnClickHandle);
			_ui.inputText.removeEventListener(KeyboardEvent.KEY_UP,InputClickHandle);
			_ui.clearBtn.removeEventListener(MouseEvent.CLICK,btnClickHandle);
			
			_ui.clearBtn.removeEventListener(MouseEvent.MOUSE_OVER,btnOverHandle);
			_ui.clearBtn.removeEventListener(MouseEvent.MOUSE_OUT,btnOutHandle);
			
			_ui.jiaBtn.removeEventListener(MouseEvent.CLICK,changeCount);
			_ui.jianBtn.removeEventListener(MouseEvent.CLICK,changeCount);
		}
		
		/**
		 *点击扫荡次数加或减 
		 * @param event
		 * 
		 */
		private function changeCount(event : MouseEvent):void
		{
			var onClickTarget : NxButton = event.currentTarget as NxButton;
			var targetText : int = int(_ui.inputText.text);
			if(onClickTarget == _ui.jiaBtn)
			{
				_ui.inputText.text = String(targetText+1);
			}
			else if(onClickTarget == _ui.jianBtn && targetText>0)
			{
				_ui.inputText.text = String(targetText-1);
			}
			changeInput();
		}
		
		private function btnOverHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.showString(StaticIni.getSwfLangStr("UIString_1000592"));
		}
		private function btnOutHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		/**
		 * 点击关闭 
		 * @param e
		 * 
		 */		
		private function closeHandle(e:NxWindowEvent):void
		{
			if(_isWipe)
			{
				AlertUI.showAlert(StaticIni.getSwfLangStr("UIString_1000084"),StaticIni.getSwfLangStr("UIString_1000088"),AlertUI.YES|AlertUI.NO,clickCloseBack,null);
			}
			else
			{
				_wipeoutTimes=1;
				_ui.hide();
			}
			
		}
		private function clickCloseBack(type:int,str:String,clickData:*):void
		{
			if(AlertUI.YES == type)//关闭扫荡
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FB_SWEEP_BREAK);
				_ui.hide();
				_wipeoutTimes=1;
				_needOpen=false;
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_CLOSE_UI,9);
			}
		}
		private function start():void
		{
			if(_currType == 1)//普通副本
			{
				if(int(_ui.inputText.text)*_oneThew<=int(_model.scene.Role.getPlayerSP()+_model.scene.Role.GetPropertiesEx("SPBonut")))
				{
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FB_SWEEP_BEGIN,_wipeTarget,0,int(_ui.inputText.text),CheckState,1,1);
					_wipeoutTimes=int(_ui.inputText.text);
				}
				
			}
			else if(_currType == 2)//精英副本
			{
				if(EliteFBUI.getInstance().created==true)
				{
					EliteFBListLogic.getInstance().WindowIsOk	=	false;
//					EliteFBUI.getInstance().showOrHide();
				}
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FB_SWEEP_BEGIN,_currCanTarget[0],0,_currCanTarget.length,CheckState,1,2);
			
			}
			else if(_currType ==3)//禁地
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FORBIDDEN_AREA_SWEEP_BEGIN,ForbiddenZoneLogic.getInstance().currTarget,CheckState);
			}
			_ui.infoTxt.htmlText="";
		}
		/**
		 * 鼠标点击事件
		 * @param	e
		 */
		private function btnClickHandle(e:MouseEvent):void 
		{
			switch (e.target) 
			{
				case _ui.starBtn:
					if(_ui.starBtn.label ==StaticIni.getSwfLangStr("UIString_1000462")) //开始扫荡
					{
						start();
					}
					else if(_ui.starBtn.label ==StaticIni.getSwfLangStr("UIString_1000463")) //取消扫荡
					{
						SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FB_SWEEP_BREAK);
						setNpcTotal(int(_ui.inputText.text));
					}
					break;
				case _ui.checkBox:
					if (_ui.checkBox.currentFrame == 1)
					{
						_ui.checkBox.gotoAndStop(2);
					}
					else
					{
						_ui.checkBox.gotoAndStop(1);
					}
					break;
				case _ui.clearBtn:
					if(!VipUI.getInstence().created)
						VipLogic.getInstence().ui.showOrHide();
					break;
				case _ui.maxBtn:
					setWipeMax();
					break;
			}
		}
		private function InputClickHandle(e:Event):void
		{
			changeInput();
		}
		private function get CheckState():int
		{
			return _ui.checkBox.currentFrame-1;
		}
		private function starget(e:CustomMsgEvent):void
		{
			_ui.npclabel.text="";
			npcArr=e.pList;
			_wipeTarget=npcArr.shift();
			_ui.aimLabel.text = StaticIni.getSwfLangStr(_wipeTarget.toString())+"";
			setNpcTotal(int(_ui.inputText.text));
		}
		/**
		 *更新怪物数量 
		 * @param val 当前的场次
		 * 
		 */		
		private function setNpcTotal(val:int):void
		{
			var str:String="";
			switch(npcArr.length)
			{
				case 2:
					str+="\n"+StaticIni.getSwfLangStr(npcArr[0].toString())+"x"+npcArr[1]*val;
					break;
				case 4:
					for(var i:int=0;i<npcArr.length;i+=2)
					{
						str+=StaticIni.getSwfLangStr(npcArr[i].toString())+"x"+npcArr[i+1]*val;
						if(i==0)
						{
							str+="\n";
						}
					}
					break;
				
				default:
					for(var j:int=0;j<npcArr.length;j+=2)
					{
						str+=StaticIni.getSwfLangStr(npcArr[j].toString())+"x"+npcArr[j+1]*val;
						if(j==0 || j==4 && npcArr.length!=6 && npcArr.length!=10)
						{
							str+=",  ";
						}
						else if(j==4 &&npcArr.length==8)
						{
							str+=",  ";
						}
						else if(j==4 &&npcArr.length==10)
						{
							str+=",  ";
						}
						else if(j == 2 ||j==6)
						{
							str+="\n";
						}
					}
					break;
			}

			_ui.npclabel.text=str;
		}
		/**设置扫荡目标**/
		public function set WipeTarget(val:int):void
		{
			_wipeTarget = val;
		}
		/***获取扫荡目标*/
		public function get WipeTarget():int
		{
			return _wipeTarget;
		}
		/**
		 *开始扫荡 
		 * @param e
		 * 
		 */		
		private function startWipe(e:CustomMsgEvent):void
		{
			addStr="";
			addStr+=StaticIni.getSwfLangStrVar("UIStr_1001895",[_CurrNum+1])+"<br>";
//			_ui.infoTxt.htmlText+=StaticIni.getSwfLangStrVar("UIStr_1001895",[_CurrNum+1]);
			addStr+=StaticIni.getSwfLangStrVar("UIStr_1001896",[_CurrNum+1])+"<br>"; //正在扫荡中
			_ui.infoTxt.htmlText = addStr;
			_isOfLine =false; //不是离线扫荡
			_isWipe = true;
			setShowState(true);
			_timer.start();
			if(_currType == 1)
			{
				//需要的体力
				_ui.needMp.text 	= String(int(_ui.inputText.text) * _oneThew);
			}
			_ui.starBtn.label =StaticIni.getSwfLangStr("UIString_1000463");
		}
		private function setui():void
		{
			if(_wipeoutTimes*_oneThew<=_model.scene.Role.getPlayerSP())
			{
				_ui.inputText.text =_wipeoutTimes.toString();
				_ui.needMp.text 	= String(int(_ui.inputText.text) * _oneThew);
				
			}
			else if(_oneThew<=_model.scene.Role.getPlayerSP())
			{
				_ui.inputText.text ="1";
				_ui.needMp.text 	= String(int(_ui.inputText.text) * _oneThew);
			}
			_date.time = int(_ui.inputText.text) * _oneTime;
			_ui.needTime.htmlText = getTimeStr(_date) ;
			setNpcTotal(int(_ui.inputText.text));
		}
		private function pic():void
		{
		
			var id:String =StaticIni.getIniVar(_wipeTarget,"Photo");
			
			_ui.picmc.source =ResPath.JPG +id + ".jpg";
			if(_currType ==1)
			{
				_ui.itemlabel.htmlText =StaticIni.getSwfLangStrVar("UIString_1000467",[StaticIni.getSwfLangStr(StaticIni.getIniVar(_wipeTarget,"DropDes"))]);
			}
			else
			{
				_ui.itemlabel.htmlText ="";
			}
		}
		/**
		 *结束扫荡 
		 * 
		 */		
		private function endWipe(e:CustomMsgEvent):void
		{
			addStr="";
			_wipeoutNum =0;
			_CurrNum =0;
			var state:int =e.pList[0];
			_isWipe= false;
			_timer.reset();
			if(_currType == 1)
			{
				setShowState(false);
				setTimeout(setui,100);
			}
			else
			{
				if(_currType==2)
				{
					EliteFBListLogic.getInstance().showInfoPage();
				}
				if(state == 0)
				{
			
					_ui.starBtn.enabled =false;
				}
				else
				{
					_ui.starBtn.enabled=true;
				}
				
			}
			_ui.starBtn.label =StaticIni.getSwfLangStr("UIString_1000462");
			setNpcTotal(int(_ui.inputText.text));
			
		}
		/**
		 * 获取按钮状态 
		 * @param isWipe  是否正在扫荡
		 * 
		 */		
		private function setShowState(isWipe:Boolean):void
		{
			if(isWipe)
			{
				_ui.jiaBtn.enabled=false;
				_ui.jianBtn.enabled=false;
				_ui.inputText.editable	= false;
				_ui.maxBtn.enabled		= false;
				_ui.checkBox.mouseEnabled	= false;
				_ui.inputText.mouseEnabled = _ui.inputText.mouseChildren =  false;
			}
			else
			{
				_ui.jiaBtn.enabled=true;
				_ui.jianBtn.enabled=true;
				_ui.checkBox.gotoAndStop(1);
				_ui.maxBtn.enabled		=true;
				_ui.inputText.editable 	= true;
				_ui.checkBox.mouseEnabled	=true;
				_ui.inputText.mouseEnabled = _ui.inputText.mouseChildren =  true;
			}
		}
		private function setuiInfo():void
		{
			setQuintessenceFB(_currCanTarget);
			_ui.aimLabel.text = StaticIni.getSwfLangStr(_currCanTarget[0]);
		}
		private function onOpenUi(e:CustomMsgEvent =null):void
		{
			_ui.starBtn.enabled =true;
			_ui.starBtn.label =StaticIni.getSwfLangStr("UIString_1000462");
			_currType =e.pList[0];
			quintessenceUI(_currType);
			setShowState(false);
			if(_currType == 1)		//普通副本
			{
				_oneThew = e.pList[1];
				_oneTime = e.pList[2];
				_wipeTarget =e.pList[3];
				_wipeoutNum =e.pList[4];
				var state:int =e.pList[5]; //自动出售状态
				if(state ==0)
				{
					_ui.checkBox.gotoAndStop(1);
				}
				else
				{
					_ui.checkBox.gotoAndStop(2);
				}
				_ui.aimLabel.text = StaticIni.getSwfLangStr(_wipeTarget.toString());
//				_ui.itemlabel.htmlText =StaticIni.getSwfLangStrVar("UIString_1000467",[StaticIni.getSwfLangStr(StaticIni.getIniVar(_wipeTarget,"DropDes"))]);
				pic();
				setUI();
			}
			else if(_currType == 2)  //精英副本
			{
				var infoArr:Array =[];
				infoArr = e.pList;
				infoArr.shift();
				_time		=infoArr.shift(); //剩余时间		
				_currCanTarget= infoArr;
				setQuintessenceFB(_currCanTarget);
				_wipeTarget =infoArr[0]
				_date.time = _time;
				_ui.needTime.htmlText = getTimeStr(_date) ;
				var targetStr:String =EliteFBListLogic.getInstance().pageName;
				_ui.aimLabel.text = StaticIni.getSwfLangStr(targetStr);
				pic();
			}
			else if(_currType ==3)  // 禁地探秘
			{
				var targetArr:Array =e.pList;
				if(targetArr.length>0)
				{
					targetArr.shift(); 
					_currCanTarget =targetArr;
					setuiInfo();
				}
				_wipeTarget =targetArr[0]
				pic();
			}
			else if(_currType == 0) //不可扫荡
			{
				NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("UIStr_1001897"));//无扫荡目标
				return;
			}
			if(_ui.created == false)
			{
				_ui.showOrHide();
			}else
			{
				var parnte:DisplayObjectContainer=WipeOutUI.getInstance().parent;
				parnte.setChildIndex(WipeOutUI.getInstance(),parnte.numChildren-1);
//					setWipeOutUI.getInstance(),DuplicatesUI.getInstance());
		}
				

			
		}
		/**
		 * 精英副本和禁地副本调用
		 * 
		 */		
		private function setQuintessenceFB(arr:Array):void
		{
			_ui.quintessenceText.htmlText ="";
			var str:String=StaticIni.getSwfLangStr("UIStr_1001892")+"<br>";
			_targetTotal = arr.length;
			for(var i:int=0;i<arr.length;i++)
			{
				str+=StaticIni.getSwfLangStr(arr[i])+"<br>";
			}
			_ui.quintessenceText.htmlText = str;
		}
		private function quintessenceUI(type:int):void
		{
			var needLv:int = int(StaticIni.getIniVar("WipeOutLevel_Need","showNeedLevel"));
			if(type == 2 || type ==3)
			{
				_ui.npclabel.visible=false;
				_ui.label1.visible =false;
				_ui.label3.visible =false;
				_ui.needMp.visible =false;
				_ui.inputText.visible= false;
				_ui.maxBtn.visible	= false;
				_ui.titleLabel2.visible=false;
				_ui.title2.visible=false;
				_ui.jiaBtn.visible=false;
				_ui.jianBtn.visible=false;
				
				_ui.quintessenceText.visible =true;
//				_ui.timelabel.y=_ui.needTime.y =289;
				if(type == 2)  //精英
				{
					if(_model.scene.Role.getVipLevel()>needLv)
					{
						_ui.needTime.visible=_ui.timelabel.visible=false;
						_ui.clearBtn.visible=false;
					}
					else
					{
						_ui.clearBtn.visible=true;
						_ui.needTime.visible=_ui.timelabel.visible=true;
					}
						
				}
				else  // 禁地
				{
					_ui.clearBtn.visible=false;
					_ui.needTime.visible=_ui.timelabel.visible=false;
				}
				
			}
			else
			{
				_ui.titleLabel2.visible=true;
				_ui.title2.visible=true;
				_ui.aimLabel.visible=true;
				_ui.npclabel.visible=true;
				_ui.label1.visible =true;
				_ui.label3.visible =true;
				_ui.needMp.visible =true;
				_ui.inputText.visible= true;
				_ui.maxBtn.visible	= true;
				_ui.jiaBtn.visible=true;
				_ui.jianBtn.visible=true;
				_ui.quintessenceText.visible =false;
//				_ui.timelabel.y=_ui.needTime.y =238;
				if(_model.scene.Role.getVipLevel()>needLv)
				{
					_ui.clearBtn.visible=false;
					_ui.needTime.visible=_ui.timelabel.visible=false;
				}
				else
				{
					_ui.clearBtn.visible=true;
					_ui.needTime.visible=_ui.timelabel.visible=true;
				}
					
			}
		}
		private function saveItem(configid:int,amout:int):void
		{
			for(var i:int=0;i<_itemVec.length;i++)
			{
				if(_itemVec[i].configid ==configid)
				{
					_itemVec[i].amout=_itemVec[i].amout+amout;
					return;
				}
				
			}
			_itemVec.push(new ItemResult(configid,amout));

		}
		private function showItem():void
		{
			var name:String="";
			for(var i:String in  _itemVec)
			{
				if(int(i) == _itemVec.length-1)
				{
					name +=StaticIni.getSwfLangStr(String(_itemVec[int(i)].configid))+"x"+_itemVec[int(i)].amout;
				}
				else
				{
					name +=StaticIni.getSwfLangStr(String(_itemVec[int(i)].configid))+"x"+_itemVec[int(i)].amout+",";
				}
			}
			if(name !="")
			{
				_ui.infoTxt.htmlText +=StaticIni.getSwfLangStrVar("UIString_1000073",[name])+"<br/>";
			}
		}
		/**
		 更新禁地副本扫荡结算 
		 * @param e
		 * 		int currtimes 
		 *  // int money	铜钱
			// int skillExp 修为
			// int  exp   经验
			// int magicCoin 元宝
			// int sellMoney 自动出售获得铜钱数 (没勾选自动出售，就是0)
			// int itemID1	物品ID1
			// int itemID2	物品ID2
			// ……
		 */		
		private function updateForbiddenResult(e:CustomMsgEvent):void
		{
			_itemVec=new Vector.<ItemResult>();
			var resultArr:Array=e.pList;
			var currTimes:int=resultArr.shift();   //当前次数
			var totalTimes:int =_currCanTarget.length; //总次数
			var gold:int=resultArr.shift();		//掉落铜钱数
			var skillExp:int =resultArr.shift();		//修为
			var magic:int=resultArr.shift();	//元宝
			var exp:int = resultArr.shift();   //经验
			var experience:int	= resultArr.shift();   //掉落的阅历
		
			var sellMoney:int=resultArr.shift(); //自动出售物品获取的铜钱
			
			if(gold!=0)
			{
				_ui.infoTxt.htmlText +=StaticIni.getSwfLangStrVar("UIString_1000346",[gold])+"<br/>"
			}
			if(skillExp!=0)
			{
				_ui.infoTxt.htmlText +=StaticIni.getSwfLangStrVar("UIString_1000452",[skillExp])+"<br/>"
			}
			_ui.infoTxt.htmlText +=StaticIni.getSwfLangStrVar("UIString_1000076",[exp])+"<br/>";
			if(experience!=0)
			{
				_ui.infoTxt.htmlText +=StaticIni.getSwfLangStrVar("UIString_1000348",[experience])+"<br/>"
			}
			if(magic !=0)
			{
				_ui.infoTxt.htmlText +=StaticIni.getSwfLangStrVar("UIString_1000347",[magic])+"<br/>"
			}
			var name	:String		= "";
			if(sellMoney!=0)
			{
				_ui.infoTxt.htmlText +=StaticIni.getSwfLangStrVar("UIString_1000077",[sellMoney])+"<br/>";
			}
			else
			{
				for(var i:int=0;i<resultArr.length;i+=2)
				{
					saveItem(resultArr[i],resultArr[i+1]);
					
				}
				showItem();
			}
			_ui.infoTxt.htmlText+=StaticIni.getSwfLangStrVar("UIStr_1001898",[currTimes])+"<br>"; //第N次结束
			_ui.infoTxt.htmlText+="<br/>";
			if(currTimes<totalTimes)
			{
				_wipeTarget=_currCanTarget[currTimes];
				_ui.aimLabel.text = StaticIni.getSwfLangStr(_currCanTarget[currTimes]);
				pic();
				_ui.infoTxt.htmlText+=StaticIni.getSwfLangStrVar("UIStr_1001895",[currTimes+1])+"<br>"; //第N+1次战斗
				_ui.infoTxt.htmlText+=StaticIni.getSwfLangStrVar("UIStr_1001896",[currTimes+1])+"<br>"; //第N+1次开始	
			}
			else if(currTimes==totalTimes)
			{
				
				//扫荡完毕
				_ui.starBtn.enabled=false;
				_isWipe=false;
			}
		}
		private function svaveResult(arr:Array):void
		{
			showResult(arr as Array);

		}
		private function showResult(arr:Array):void
		{
			var infoArr	:Array =arr.concat();
		
			var total:Number = infoArr.shift(); //总次数
			var surpleus:int = infoArr.shift();//剩余次数
			_CurrNum = total-surpleus+1;
			if(_isOfLine) //离线扫荡
			{
				addStr+=StaticIni.getSwfLangStrVar("UIStr_1001895",[_CurrNum]); //第N开始
				addStr+=StaticIni.getSwfLangStrVar("UIStr_1001896",[_CurrNum])+"<br>"; //正在扫荡中
			}
			
			var num:int=(int(_ui.inputText.text))-1
			if(num<=0)
			{
				num =0;	
			}
			_ui.inputText.text = (surpleus-1).toString();
			_ui.needMp.text 	= String(int(_ui.inputText.text) * _oneThew);
			
			var exp		:int		= infoArr.shift();
			var sp		:int 		= infoArr.shift();
			var gold	:int 		= infoArr.shift();
			var money	:int		= infoArr.shift();
			
			var experience:int		= infoArr.shift();   //掉落的阅历
			var copperplate:int		= infoArr.shift();   //掉落的铜钱
			var magic:int			= infoArr.shift();   //掉落的元宝
			var name	:String		= "";
			for(var i:int=0;i<infoArr.length;i+=2)
			{
				if(i == infoArr.length-2)
				{
					name +=StaticIni.getSwfLangStr(infoArr[i])+"x"+infoArr[i+1];
				}
				else
				{
					name +=StaticIni.getSwfLangStr(infoArr[i])+"x"+infoArr[i+1]+",";
				}
			}
			if(money ==0) //没有自动出售
			{
				if(name !="")
				{
					addStr+=StaticIni.getSwfLangStrVar("UIString_1000073",[name])+"<br/>";
				}
				
			}//自动出售
			else
			{
				addStr+=StaticIni.getSwfLangStrVar("UIString_1000077",[money])+"<br/>";
			}
			if(gold>0) //立即完成
			{
				addStr+=StaticIni.getSwfLangStrVar("UIString_1000074",[gold])+"<br/>";
			}
			addStr+=StaticIni.getSwfLangStrVar("UIString_1000075",[sp])+"<br/>";
			addStr+=StaticIni.getSwfLangStrVar("UIString_1000076",[exp])+"<br/>";
			if(experience!=0)
			{
				addStr+=StaticIni.getSwfLangStrVar("UIString_1000348",[experience])+"<br/>"
			}
			if(copperplate!=0)
			{
				addStr+=StaticIni.getSwfLangStrVar("UIString_1000346",[copperplate])+"<br/>"
			}
			if(magic!=0)
			{
				addStr+=StaticIni.getSwfLangStrVar("UIString_1000347",[magic])+"<br/>"
			}
			addStr+=StaticIni.getSwfLangStrVar("UIStr_1001898",[_CurrNum])+"<br>"; //第N次结束
			addStr+="<br/>";
			if(_isOfLine)
				return;
			if(_currType == 1)
			{
				if(_CurrNum+1<=total)
				{
					addStr+=StaticIni.getSwfLangStrVar("UIStr_1001895",[_CurrNum+1])+"<br>"; //第N+1次战斗
					addStr+=StaticIni.getSwfLangStrVar("UIStr_1001896",[_CurrNum+1])+"<br>"; //第N+1次开始	
				}
				setNpcTotal(surpleus-1);
			}
			else if(_currType == 2)
			{
				if(_CurrNum+1<=_targetTotal)
				{
					_wipeTarget=_currCanTarget[_CurrNum]
					_ui.aimLabel.text = StaticIni.getSwfLangStr(_currCanTarget[_CurrNum]);
					pic();
					addStr+=StaticIni.getSwfLangStrVar("UIStr_1001895",[_CurrNum+1])+"<br>"; //第N+1次战斗
					addStr+=StaticIni.getSwfLangStrVar("UIStr_1001896",[_CurrNum+1])+"<br>"; //
				}
			}

			if(_CurrNum>SHOW_LEN)
			{
				var str:String =StaticIni.getSwfLangStrVar("UIStr_1001898",[_CurrNum-SHOW_LEN]);
				var index:int= addStr.search(str);
				_ui.infoTxt.htmlText=addStr.substring(index,addStr.length);
			}
			else
			{
				_ui.infoTxt.htmlText=addStr;
			}
		
//			_resultStrIndex.push(addStr);
		}
		/**
		 * 更新一次结算信息  exp  sp  gold(消耗) money(获得) 阅历(掉落) 铜钱(掉落) 元宝(掉落) configID 
		 * @param e
		 * 
		 */		
		private function updateResult(e:CustomMsgEvent):void
		{	
			
			if(_ui.created ==false)
			{
				_ui.showOrHide();
			}
			svaveResult(e.pList);
		
			
		}
		private function changeInput():void
		{
			var currThew:int= _model.scene.Role.GetPropertiesEx("SP")+_model.scene.Role.GetPropertiesEx("SPBonut");
			var count:int = currThew/_oneThew;
			if(int(_ui.inputText.text) > count)
			{
				_ui.inputText.text = String(count);
			}
	
			setBtnShow();
			setNpcTotal(int(_ui.inputText.text));
		}
		private function setUI():void
		{
			//当前体力
			var currThew:int = _model.scene.Role.GetPropertiesEx("SP")+_model.scene.Role.GetPropertiesEx("SPBonut");
			if(currThew < _oneThew)
			{
				_ui.needMp.htmlStr = StaticIni.getSwfLangStrVar("UIStr_1001746",[_oneThew]);
				_ui.inputText.text = "0";
			}else
			{
				var num:int=1;
				var total:int =_oneThew;
				//有离线剩余次数
				if(_wipeoutNum >0)
				{
					total =_oneThew*_wipeoutNum;
					num	  =_wipeoutNum;
				}
				_ui.needMp.htmlStr = StaticIni.getSwfLangStrVar("UIStr_1001745",[total]);
				_ui.inputText.text = num.toString();
			}
			setBtnShow();
			
		}
		/**
		 *设置最大扫荡次数 
		 * 
		 */		
		private function setWipeMax():void
		{
			var currThew:int = _model.scene.Role.GetPropertiesEx("SP")+_model.scene.Role.GetPropertiesEx("SPBonut");
			var count:int = currThew/_oneThew;
			_ui.inputText.text = String(count);
			setBtnShow();
			setNpcTotal(int(_ui.inputText.text));
		}
		private function setBtnShow():void
		{
			//需要的体力
			_ui.needMp.text 	= String(int(_ui.inputText.text) * _oneThew);
			//需要的时间
			_date.time			= int(_ui.inputText.text) * _oneTime;
			_ui.needTime.text	= getTimeStr(_date);
		}
		private function PalyeTime(e:TimerEvent):void
		{
			_date.time -=1000
			_ui.needTime.text	= getTimeStr(_date);
			if(_date.time<=0)
			{
				_date.time			= int(_ui.inputText.text) * _oneTime;
				_ui.needTime.text	= getTimeStr(_date);
				_timer.reset();
			}
			
		}
		/**
		 * 获取时间字符串 
		 * @param date
		 * @return 
		 * 
		 */		
		private function getTimeStr(date:Date):String
		{
			var hours  :int  = date.hoursUTC;
			var minutes:int  = date.minutesUTC;
			var seconds:int  = date.secondsUTC;
			var str:String   = initTime(hours)+":"+initTime(minutes)+":"+initTime(seconds);
			return str;
		}
		
		/**
		 * 格式时间 
		 * @param val
		 * @return 
		 * 
		 */		
		private function initTime(val:int):String
		{
			var  va:String = val.toString();
			val>9?va:va="0"+va;
			return va;
		}
		private function clearAll():void
		{
			_ui.title2.mouseChildren =_ui.title2.mouseEnabled =false;
			_ui.checkBox.gotoAndStop(1);
//			_ui.infoTxt.text	=	"";
		}
		public function get WipeState():Boolean
		{
			return  _isWipe;
		}
		private function onShowTips(e:MouseEvent):void
		{
		}
		private function updateTips(e:CustomMsgEvent):void
		{
			var str:String = StaticIni.getSwfLangStrVar("UIString_1000079",[e.pList[0]]);
			TipsMainLogic.instance.showString(str);
		}
		private function onHideTips(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
	}
}
class ItemResult
{
	public var configid:int;
	public var amout:int;
	public function ItemResult(configid:int,amout:int):void
	{
		this.configid =configid;
		this.amout=amout;
	}
}